package com.gh.shopmall.product.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.gh.common.valid.AddGroup;
import com.gh.common.valid.ListValue;
import com.gh.common.valid.UpdateGroup;
import lombok.Data;
import org.hibernate.validator.constraints.URL;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.util.List;

/**
 * 商品三级分类
 *
 * @author Eric Fang
 * @email tomcat@126.com
 * @date 2021-11-13 19:49:58
 */
@Data
@TableName("pms_category")
public class CategoryEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 分类id
     */
    @NotNull(message = "修改不能为空", groups = AddGroup.class)
    @Null(message = "新增必须为空", groups = AddGroup.class)
    @TableId
    private Long catId;
    /**
     * 分类名称
     */
    @NotNull
    private String name;
    /**
     * 父分类id
     */
    private Long parentCid;
    /**
     * 层级
     */
    private Integer catLevel;
    /**
     * 是否显示[0-不显示，1显示]
     */
    @ListValue(vals = {0, 1}, groups = UpdateGroup.class)
    @TableLogic(value = "1", delval = "0")
    private Integer showStatus;
    /**
     * 排序
     */
    private Integer sort;
    /**
     * 图标地址
     */
    @URL(message = "logo必须是一个合法的url")
    private String icon;
    /**
     * 计量单位
     */
    @Pattern(regexp = "^[a-zA-Z]$", message = "检索首字母必须是一个字母")
    private String productUnit;
    /**
     * 商品数量
     */
    private Integer productCount;

    @JsonInclude(value = JsonInclude.Include.NON_EMPTY)
    @TableField(exist = false)
    private List<CategoryEntity> children;

}
